package com.ruoyi.read.service.impl;

import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.function.impl.ToDouble;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.read.mapper.SysNoticeReadMapper;
import com.ruoyi.read.domain.SysNoticeRead;
import com.ruoyi.read.service.ISysNoticeReadService;

/**
 * readService业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-13
 */
@Service
public class SysNoticeReadServiceImpl implements ISysNoticeReadService 
{
    @Autowired
    private SysNoticeReadMapper sysNoticeReadMapper;


    @Autowired
    private TokenService tokenService;

    /**
     * 查询read
     * 
     * @param id readID
     * @return read
     */
    @Override
    public SysNoticeRead selectSysNoticeReadById(Long id)
    {
        return sysNoticeReadMapper.selectSysNoticeReadById(id);
    }

    /**
     * 查询read列表
     * 
     * @param sysNoticeRead read
     * @return read
     */
    @Override
    public List<SysNoticeRead> selectSysNoticeReadList(SysNoticeRead sysNoticeRead)
    {
        return sysNoticeReadMapper.selectSysNoticeReadList(sysNoticeRead);
    }

    /**
     * 新增read
     * 
     * @param sysNoticeRead read
     * @return 结果
     */
    @Override
    public int insertSysNoticeRead(SysNoticeRead sysNoticeRead)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        sysNoticeRead.setUserId(loginUser.getUser().getUserId());
        SysNoticeRead r = sysNoticeReadMapper.selectSysNoticeReadByUserIdAndNoticeId(sysNoticeRead);
        if (ObjectUtil.isNotNull(r)){
            return 1;
        }
        return sysNoticeReadMapper.insertSysNoticeRead(sysNoticeRead);
    }

    /**
     * 修改read
     * 
     * @param sysNoticeRead read
     * @return 结果
     */
    @Override
    public int updateSysNoticeRead(SysNoticeRead sysNoticeRead)
    {
        return sysNoticeReadMapper.updateSysNoticeRead(sysNoticeRead);
    }

    /**
     * 批量删除read
     * 
     * @param ids 需要删除的readID
     * @return 结果
     */
    @Override
    public int deleteSysNoticeReadByIds(Long[] ids)
    {
        return sysNoticeReadMapper.deleteSysNoticeReadByIds(ids);
    }

    /**
     * 删除read信息
     * 
     * @param id readID
     * @return 结果
     */
    @Override
    public int deleteSysNoticeReadById(Long id)
    {
        return sysNoticeReadMapper.deleteSysNoticeReadById(id);
    }
}
